package dyyx.util;

import java.util.Random;

import org.apache.commons.lang3.StringUtils;

import dyyx.dto.AsClient;


public abstract class AsUtil {
	// private static final Random RAND = new Random();
	
	private static volatile AsClient client;

	
	public static synchronized void connect(String server)throws Exception{
		if(client!=null){
			throw new Exception("connected"); 
		}
		
		if(StringUtils.isBlank(server)){
			throw new Exception("aerospike server blank"); 
		}
		
		
        AsClient clienttmp = new AsClient(server);
		client = clienttmp;			
	}
	
	public static synchronized AsClient getClient(){
		if(client==null){
			throw new RuntimeException("not connected"); 
		}
		return client;
	}
	
	public static synchronized void disconnect()throws Exception{
		if(client==null){
			throw new Exception("not connected"); 
		}
		client.client.close();
		client = null;
	}
	
	

}
